﻿using Excel = Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Extensibility;

namespace 枸杞Excel插件.ThisAddin
{
    [ComVisible(true)]
    [Guid("6DE8BC11-B208-4587-A509-AEC6D66D76EF")]
    [ProgId("枸杞Excel插件")]
    public partial class ThisAddin : IDTExtensibility2
    {
        public Excel.Application? Application;

        public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
        {
            this.Application = (Excel.Application)Application;
            if (ConnectMode != ext_ConnectMode.ext_cm_Startup)//用户手动加载时不触发OnStartupComplete,强制触发
            {
                OnStartupComplete(ref custom);
            }
        }

        public void OnStartupComplete(ref Array custom)
        {
            ThisAddIn_Startup();
        }

        public void OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom)
        {
            if (RemoveMode != ext_DisconnectMode.ext_dm_HostShutdown)//用户手动取消加载时不触发OnBeginShutdown,强制触发
            {
                OnBeginShutdown(ref custom);
            }
        }

        public void OnBeginShutdown(ref Array custom)
        {
            ThisAddIn_Shutdown();
        }

        public void OnAddInsUpdate(ref Array custom)
        {
            //插件列表更新时触发,没有用
        }
    }
}